<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@include file="/WEB-INF/base.jspf"%>
<style>
 #test1 {
	 margin: 2px;  
	 height: 37px;
}

#test2 {
	margin: 2px;
	height: 37px;
}

#qblx {
	margin: 2px;
	height: 37px;
}
	.modal-dialog {
		max-width: 1000px;
	}
#zflx {
	margin: 2px;
	height: 37px;
}

.layui-inline {
	height: 100px;
	margin-top:15px;
}

#hymc {
	margin: 2px;
	height: 45px;
}

p {
	margin:7px;
} 
#table_id_example_paginate{
 margin-right:100px;
}
.class-input-pageNumber{
    
	width:40px;
	height:23px;
	position: absolute;
	right:550px;
	top:12px;
}
.class-span-searchBtn{
	height:24px;
	width:36px;
	font-size:14px;
	text-algin:center;
	line-height:25px;
	padding:0!important;
	position: absolute;
	right:500px;
	top:12px;
}
.dataTables_length{
	margin-top:12px;
	margin-left:50px;
}
.tableSearch{
    position: relative;
}
.hidden-c {
	display:none;
}

.btn-c-dealShenQing {
	display:none;
}
table th,table tr,table td {
text-align: center;
vertical-align:middle;
}
#activateBtn{
width:54px;
height:34px;
}
.object{
width:146px;
margin-left:1px;
}
</style>
				<div class="layui-inline">
					<br> 
					<input type="text" id="hymc" placeholder="请输入会员名称"> 
					<button class="layui-btn layui-btn-radius" id="btn_search" >查询</button>
					<button class="layui-btn layui-btn-radius" id="button-i-resetTableContent" style="margin-left:5px;">重置</button>
				</div>
			<div>
			   <table class="class-tableDataTable class-table-needClick display table table-striped table-bordered table-hover" id="hydaml">
					<thead>
						<tr>
							<th>用户账号</th>
							<th>当前打码</th>
							<th>提款所需</th>
							<th>变动时间</th>
							<th>打码状态</th>
							<th>打码操作</th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
	<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">打码操作</h4>
					</div>
					<div class="modal-body">
								      <input type="hidden" id="id" value="">
								      <input type="hidden" id="userid" value="">
								<p style="display:flex;align-items:center;"><span style="width:80px;display:inline-block;">会员账号:</span><input class="object form-control" id="account" value="" readonly></p>
								<p style="display:flex;align-items:center;"><span style="width:80px;display:inline-block;">当前打码量:</span><input class="object form-control" id="dangqiansx" value="" readonly></p>
								<p style="display:flex;align-items:center;"><span style="width:80px;display:inline-block;">提款所需量: </span><input class="object form-control" id="tikuansx" value="" readonly></p>
								<p style="display:flex;align-items:center;">
								<span style="width:80px;display:inline-block;">操作类型:</span>				
									<select class="btn btn-default"  id="bdtype">
										<option value="">请选择操作类型</option>
										<option value="人工增加">人工增加</option>
										<option value="人工扣除">人工扣除</option>
									</select>
								</p>
								<p style="display:flex;align-items:center;"><span style="width:80px;display:inline-block;">
								操作数量:</span><input style="width:146px;" class="form-control" type="text" id="fukuanje" placeholder="操作数量" ></p>
								<p style="display:flex;align-items:center;"><span style="width:80px;display:inline-block;">
								操作原因:</span><textarea class="form-control" id="beizhu" placeholder="操作原因" maxlength="50" style="resize: none;width:auto;flex-grow:1;" ></textarea></p>	
					</div>					
					<div class="modal-footer">
					<button type="button" id="closeBtn" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" id="submitBtn" class="btn btn-primary">提交更改</button>
				</div>
			</div>
		</div>
	</div>
</div>
	<script>
	var modal = $("#editModal");
	modal.on("show.bs.modal", function(e) {    
	    var btn = $(e.relatedTarget),
	        id = btn.data("id");
	    $("#id").val(id);
	    $("#account").val(btn.data("huiyuanzh")); 
	    $("#tikuansx").val(btn.data("tikuansx"));
	    $("#dangqiansx").val(btn.data("damaliang"));
	    $("#userid").val(btn.data("userid"));
	  });
	  $('#submitBtn').click(function () {
		  	if($('#id').val()==""){
	  			alert('参数出错!');
				return false;
			}
		  	if($('#bdtype').val()==""){
		  		alert('请选择操作类型!');
	  			return false;
	  		}
		  	$.ajax({
	            dataType: "json",
	            type: "post",
	            url: "/zhgl/updateCodeCount.do",
	            data: { 
	            	"userid": $('#userid').val(),
	            	"huiyuanzh":$("#account").val(),
	            	"bdtype": $('#bdtype').val(),
	            	"bdcount": $('#fukuanje').val(),
	            	"beizhu": $('#beizhu').val()},
	            success: function (data) {
	            	$('#editModal').modal('hide');
	            	alert(data.data);
	            	var table = $('#hydaml').DataTable();			
	    			table.ajax.url("/zhgl/findAllUserCodeInfo.do").load();
	            }
	        });
	   });	
	
	$("#hydaml").on("click",".btn-state",function(){
		var userid=$(this).parent().next().find(".btn-sm").attr("data-userid");
		var name=$(this).parents().find("td:eq(0)").text();
		var state;
		if($(this).text()=="开启"){
			state=0;
		}else{
			state=1;	
		}
		$.ajax({
            dataType: "json",
            type: "post",
            url: "/zhgl/updateUserCodeState.do",
            data: {
            	"id": userid, 
            	"state": state,
            	'name': name
            	},
            success: function (data) {
            	alert(data.data);
            	var table = $('#hydaml').DataTable();			
    			table.ajax.url("/zhgl/findAllUserCodeInfo.do").load();
            },
            error: function (data) {
                console.log('error');
            }
        })
	})
	
	function dataTable01(){
		$("#hydaml").DataTable({
	      // "bPaginate": true,
	      "bLengthChange": true,      
	      "bSort": false,
	      // "bInfo": true,
	      "bAutoWidth": false,
//	         "bServerSide":true,
		      'aLengthMenu':[5,10, 20],
		       "searching": true, 
		       "dom": "t<'tableinfo'i<'tableSearch'p>l>",
	       "language": {//语言设置  
	            "lengthMenu": "每页显示 _MENU_ 条记录",     
	            "zeroRecords": "没有检索到数据",     
	            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",     
	            "info": "没有数据",     
	            "oPaginate": {     
	                "sFirst": "首页",     
	                "sPrevious": "前一页",     
	                "sNext": "后一页",     
	                "sLast": "尾页"    
	          	},
	            "search":"搜索:",
	            "infoFiltered":   "(从  _MAX_ 记录中搜索出结果)",
	            "infoEmpty":      "没有找到匹配的信息",
	         },
		         "columns": [
	                     { "data": "huiyuanzh" },
	                     { "data": "damaliang" },
	                     { "data": "tikuansx" },
	                     { "data": "createtime" },
	                     { 
	                         "data": "userid",
	                         "orderable": false,
	                         "width": "15%",
	                         "render": function(data,type,row,meta){
	                        	  if(row.state==1)
	                                return data = "<button class='btn btn-primary btn-sm btn-state  data-toggle='modal'>开启</button>";
	                             else
	                            	return data = '<button class="btn btn-success btn-sm btn-state"  data-toggle="modal">关闭</button>';   	 
	                         }
	                     },
	                     {
	                         "data": "id",
	                         "orderable": false,
	                         "width": "15%",
	                         "render": function(data,type,row,meta){
	                                return data = '<button class="btn btn-success btn-sm " data-id=' + data + ' data-huiyuanzh=' + row.huiyuanzh 
	                                + ' data-damaliang=' + row.damaliang + ' data-tikuansx=' + row.tikuansx + ' data-toggle="modal" data-target="#editModal" data-userid="' + row.userid + '">修改</button>';
	                         }
	                     }	                     
	                 ],		                 
		      "ajax": {
	    	  	  "type": 'POST',
	    	      "url":"/zhgl/findAllUserCodeInfo.do", 
		    	  "data": function ( d ) {
		    	        d.huiyuanzh = $('#hymc').val();
		    	    }
		      },	       
	    })
	}
	dataTable01();
	insertSearchBtn();
	document.querySelector("#btn_search").addEventListener("click", function(event) {
		var table = $('#hydaml').DataTable();			
		table.ajax.url("/zhgl/likeFindUserCodeInfo.do").load();
	})
		$("#button-i-resetTableContent").on("click", function(event) {
		var table = $('#hydaml').DataTable();			
		table.ajax.url("/zhgl/findAllUserCodeInfo.do").load();
         $('#hymc').val("");
	})
	</script>
